import java.util.*;
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Text {
    //242
    public boolean isAnagram(String s, String t) {
        Map<Character,Integer> hashmap = new HashMap<>();
        for(int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            hashmap.put(ch,hashmap.getOrDefault(ch,0)+1);
        }
        for(int i = 0; i < t.length(); i++) {
            char  ch = t.charAt(i);
            if(hashmap.containsKey(ch) && hashmap.get(ch) != 0) {
                hashmap.put(ch,hashmap.get(ch)-1);
            }else {
                return false;
            }
        }
        for(int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(hashmap.get(ch) != 0) {
                return false;
            }
        }
        return true;
    }
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode prev = new ListNode(0);
        ListNode cur = prev;
        int carry = 0;
        while(l1 != null || l2 != null) {
            int num1 = (l1 == null ? 0 : l1.val);
            int num2 = (l2 == null ? 0 : l2.val);
            int sum = num1+num2+carry;
            carry = sum/10;
            ListNode root = new ListNode(sum%10);
            cur.next = root;
            cur = cur.next;
            if(l1 != null) {
                l1 = l1.next;
            }
            if(l2 != null) {
                l2 = l2.next;
            }
        }
        if(carry == 1) {
            cur.next = new ListNode(carry);
        }
        return prev.next;
    }
}
